

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busPhotoAlbums:BusinessBase
	{
		public busPhotoAlbums() : base()
		{
		}
		#region  Code Factory Generated Methods
		
		
		public DataTable SelectPhotoAlbums()
		{
			try
			{
				datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
				DbConnector insDbConnector = new DbConnector();
				return insDatPhotoAlbums.SelectPhotoAlbums(insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage = ex.Message;
			}
			return null;
		}
		public void SelectPhotoAlbumsByPhotoAlbumId(entPhotoAlbums parEntPhotoAlbums)
		{
			try
			{
				datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
				DbConnector insDbConnector = new DbConnector();
				insDatPhotoAlbums.SelectPhotoAlbumsByPhotoAlbumId(parEntPhotoAlbums, insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage=ex.Message;
			}
		}
		
		#endregion
        public void InsertPhotoAlbums(entPhotoAlbums parEntPhotoAlbums)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
                insDatPhotoAlbums.InsertPhotoAlbums(parEntPhotoAlbums, insDbConnector);
                datPhotoAlbumContents insDatPhotoAlbumContents = new datPhotoAlbumContents();
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsInsert)
                {
                    insEntPhotoAlbumContents.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                    insDatPhotoAlbumContents.InsertPhotoAlbumContents(insEntPhotoAlbumContents, insDbConnector);
                }
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsUpdate)
                {
                    insEntPhotoAlbumContents.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                    insDatPhotoAlbumContents.UpdatePhotoAlbumContentsByPhotoAlbumContentId(insEntPhotoAlbumContents, insDbConnector);
                }
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsDelete)
                {
                    insDatPhotoAlbumContents.DeletePhotoAlbumContentsByPhotoAlbumContentId(insEntPhotoAlbumContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdatePhotoAlbumsByPhotoAlbumId(entPhotoAlbums parEntPhotoAlbums)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
                insDatPhotoAlbums.UpdatePhotoAlbumsByPhotoAlbumId(parEntPhotoAlbums, insDbConnector);
                datPhotoAlbumContents insDatPhotoAlbumContents = new datPhotoAlbumContents();
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsInsert)
                {
                    insEntPhotoAlbumContents.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                    insDatPhotoAlbumContents.InsertPhotoAlbumContents(insEntPhotoAlbumContents, insDbConnector);
                }
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsUpdate)
                {
                    insEntPhotoAlbumContents.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                    insDatPhotoAlbumContents.UpdatePhotoAlbumContentsByPhotoAlbumContentId(insEntPhotoAlbumContents, insDbConnector);
                }
                foreach (entPhotoAlbumContents insEntPhotoAlbumContents in parEntPhotoAlbums.PhotoAlbumContentsDelete)
                {
                    insDatPhotoAlbumContents.DeletePhotoAlbumContentsByPhotoAlbumContentId(insEntPhotoAlbumContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }

        public void DeletePhotoAlbumsByPhotoAlbumId(entPhotoAlbums parEntPhotoAlbums)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDbConnector.BeginTransaction();

                datPhotos insDatPhotos = new datPhotos();
                entPhotos insEntPhotos = new entPhotos();
                insEntPhotos.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                if (insDatPhotos.SelectPhotosByPhotoAlbumId(insEntPhotos, insDbConnector).Rows.Count > 0)
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(44, new object[] { }));
                }

                datPhotoAlbumContents insDatPhotoAlbumContents = new datPhotoAlbumContents();
                entPhotoAlbumContents insEntPhotoAlbumContents = new entPhotoAlbumContents();
                insEntPhotoAlbumContents.PhotoAlbumId = parEntPhotoAlbums.PhotoAlbumId;
                insDatPhotoAlbumContents.DeletePhotoAlbumContentsByPhotoAlbumId(insEntPhotoAlbumContents, insDbConnector);

                datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
                insDatPhotoAlbums.DeletePhotoAlbumsByPhotoAlbumId(parEntPhotoAlbums, insDbConnector);

                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public DataTable SelectPhotoAlbumsByLanguageId()
        {
            try
            {
                datPhotoAlbums insDatPhotoAlbums = new datPhotoAlbums();
                DbConnector insDbConnector = new DbConnector();
                return insDatPhotoAlbums.SelectPhotoAlbumsByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
	}
}